// class mzhttpd


#ifndef _MZHTTPD_H_
#define _MZHTTPD_H_

#include <stdio.h>           // FILE
#include <sys/types.h>    // u_short

#include "mzhttp.h"

class Mzhttpd
{
public:
	// construct and destruct
	Mzhttpd();
	Mzhttpd(u_short port);
	virtual ~Mzhttpd();
	
	int startup();           // init server
	void run();                           // start and run


private:
	// handle requests
	static void* accept_request(int _client);
	
	// http method
	static void headers(int client, const char *filename);   // 200
	static void bad_request(int client);                    // 400
	static void not_found(int client);                      // 404
	static void cannot_execute(int client);                 // 500
	static void unimplemented(int client);                  // 501
	
	static void cat(int client, FILE *resource);
	static void execute_cgi(int client, const char *path,
                 const char *method, const char *query_string);
    static int get_line(int sock, char *buf, int size);
    
    static unsigned long get_file_size(const char *filename);             // help serve_file
    static void serve_file_headers(int client, const char *filename, unsigned long fsize);
    static void serve_file(int client, const char *filename);
    static void serve_route(int client, const char* buf);   // mzroute
    
    
    
	// report error
	void error_die(const char *sc);
	
	// members
	u_short port;          // run on which port

};



#endif 
